--- 模块功能：通用工具
-- @author zgt
-- @module tools
-- @license MIT
-- @copyright zgt
-- @release 2022-6-20 20:14:00
module(..., package.seeall)
--[[发送modbus数据函数
@function   modbus_send
@param      uid: 对应串口id
            slaveaddr : 从站地址
            Instructions:功能码
		    reg : 寄存器编号
            value : 写入寄存器值或读取寄存器个数,2字节
@return     无
@usage modbus_send(3,"0x01","0x03","0x0101","0x04")
]]
function modbus_send(uid,slaveaddr,Instructions,reg,value)
    local data =(string.format("%02x",slaveaddr)..string.format("%02x",Instructions)..string.format("%04x",reg)..string.format("%04x",value)):fromHex()
    local modbus_crc_data= pack.pack('<h', crypto.crc16("MODBUS",data))
    local data_tx = data..modbus_crc_data
    sys.publish("UART_SENT_RDY_" .. uid,uid, data_tx)
end
